#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>

using namespace std;

#define FILEPATH "./myname.bin"
//#define NUMINTS  262144

class MMapParser  {

	int *header,*JC_CP, JC_SIZE, CP_SIZE, IR_SIZE;

	void init(){

	}
};

void do_mmap() {

	int fd = open(FILEPATH, O_RDONLY);
	struct stat fs;

	if (fd == -1) {
		perror("Error opening file for reading");
		exit (EXIT_FAILURE);
	}

	if (fstat(fd, &fs) == -1) {
		perror("Error on fstat");
		exit(EXIT_FAILURE);
	}

	void * map = mmap(0, fs.st_size, PROT_READ, MAP_SHARED, fd, 0);

	if (map == MAP_FAILED) {
		close(fd);
		perror("Error mmapping the file");
		exit (EXIT_FAILURE);
	}
	char * cptr = (char*) map;


	printf("\n", "");

	if (munmap(map, fs.st_size) == -1) {
		perror("Error un-mmapping the file");
	}

	close(fd);
	printf("finished\n ");
}



int main(int argc, char *argv[]) {
	do_mmap();

return 0;
}


